package com.CMS.server.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = EntityTokens.MENU_TABLE)
public class Menu extends BaseEntity{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2750595194273132366L;

	public Menu(){
		super();
	}
	
	@ManyToMany(fetch = FetchType.EAGER, cascade ={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
	@JoinTable
	(
		name = "MENU_ITEM",
		joinColumns={@JoinColumn(name="ID_MENU",referencedColumnName="ID")},
		inverseJoinColumns={@JoinColumn(name = "ID_ITEM",referencedColumnName="ID")}
	)
	protected List<ItemMenu> items;

	public List<ItemMenu> getItems() {
		return items;
	}

	public void setItems(List<ItemMenu> items) {
		this.items = items;
	}
	
	public void addItem(ItemMenu item){
		this.items.add(item);
	}
}
